import store from '@/store';
import { resetRouter } from '@/router';
import globalApi from '@/api';

export default {
	getToken() {
		const token = localStorage.getItem('token');
		if (token === 'undefined') return;
		return token;
	},
	setToken(token) {
		localStorage.setItem('token', token);
	},
	hasToken() {
		return !!this.getToken();
	},
	removeToken() {
		localStorage.removeItem('token');
	},
	async logout() {
		try {
      await globalApi.login.logoutApi();
    } catch (err) {

    } finally {
      this.removeToken();
      store.commit('logout');
      resetRouter();
    }
	}
};
